// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MATERIAL_ITEM_RECORD_MFN_M16 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 MFE",6)]
  	    [HL7Field(HL7Version.v26, 6, HL7Repeat.False, HL7Required.True,"MFE")]
	    public MFE MFE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("7 ITM",7)]
  	    [HL7Field(HL7Version.v26, 7, HL7Repeat.False, HL7Required.True,"ITM")]
	    public ITM ITM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 NTE",8)]
  	    [HL7Field(HL7Version.v26, 8, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 STERILIZATION",9)]
  	    [HL7Field(HL7Version.v26, 9, HL7Repeat.True, HL7Required.False,"STERILIZATION_MFN_M16")]
	    public STERILIZATION_MFN_M16[] STERILIZATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("13 PURCHASING_VENDOR",13)]
  	    [HL7Field(HL7Version.v26, 13, HL7Repeat.True, HL7Required.False,"PURCHASING_VENDOR_MFN_M16")]
	    public PURCHASING_VENDOR_MFN_M16[] PURCHASING_VENDOR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 MATERIAL_LOCATION",20)]
  	    [HL7Field(HL7Version.v26, 20, HL7Repeat.True, HL7Required.False,"MATERIAL_LOCATION_MFN_M16")]
	    public MATERIAL_LOCATION_MFN_M16[] MATERIAL_LOCATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			MFE = PopSegmentParseAndCheckRequired<MFE>(availableData, options, "MFE");
			ITM = PopSegmentParseAndCheckRequired<ITM>(availableData, options, "ITM");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			STERILIZATION = ProcessGroupArray<STERILIZATION_MFN_M16>(availableData, options, "STERILIZATION");
			PURCHASING_VENDOR = ProcessGroupArray<PURCHASING_VENDOR_MFN_M16>(availableData, options, "PURCHASING_VENDOR");
			MATERIAL_LOCATION = ProcessGroupArray<MATERIAL_LOCATION_MFN_M16>(availableData, options, "MATERIAL_LOCATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isMFE = availableData.StartsWith("MFE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("MFE", options.Version) || isMFE) {
				return isMFE;
			}
			bool isITM = availableData.StartsWith("ITM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ITM", options.Version) || isITM) {
				return isITM;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			STERILIZATION_MFN_M16 testSTERILIZATION_MFN_M16 = new STERILIZATION_MFN_M16();
			bool grpCCSTERILIZATION_MFN_M16 = (testSTERILIZATION_MFN_M16.CanConsume(availableData, options));
			if (IsRequired("STERILIZATION", options.Version) || grpCCSTERILIZATION_MFN_M16) {
				return grpCCSTERILIZATION_MFN_M16;
			}
			PURCHASING_VENDOR_MFN_M16 testPURCHASING_VENDOR_MFN_M16 = new PURCHASING_VENDOR_MFN_M16();
			bool grpCCPURCHASING_VENDOR_MFN_M16 = (testPURCHASING_VENDOR_MFN_M16.CanConsume(availableData, options));
			if (IsRequired("PURCHASING_VENDOR", options.Version) || grpCCPURCHASING_VENDOR_MFN_M16) {
				return grpCCPURCHASING_VENDOR_MFN_M16;
			}
			MATERIAL_LOCATION_MFN_M16 testMATERIAL_LOCATION_MFN_M16 = new MATERIAL_LOCATION_MFN_M16();
			bool grpCCMATERIAL_LOCATION_MFN_M16 = (testMATERIAL_LOCATION_MFN_M16.CanConsume(availableData, options));
			if (IsRequired("MATERIAL_LOCATION", options.Version) || grpCCMATERIAL_LOCATION_MFN_M16) {
				return grpCCMATERIAL_LOCATION_MFN_M16;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MATERIAL_ITEM_RECORD";
			}
        }

        static MATERIAL_ITEM_RECORD_MFN_M16() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MATERIAL_ITEM_RECORD_MFN_M16));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (MFE != null) {
			string segmentValue = MFE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ITM != null) {
			string segmentValue = ITM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (STERILIZATION != null && STERILIZATION.Length > 0) {
			for (int i = 0; i < STERILIZATION.Length; i++) {
				string segmentValue = STERILIZATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PURCHASING_VENDOR != null && PURCHASING_VENDOR.Length > 0) {
			for (int i = 0; i < PURCHASING_VENDOR.Length; i++) {
				string segmentValue = PURCHASING_VENDOR[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (MATERIAL_LOCATION != null && MATERIAL_LOCATION.Length > 0) {
			for (int i = 0; i < MATERIAL_LOCATION.Length; i++) {
				string segmentValue = MATERIAL_LOCATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

